/**
 * 
 */
package com.firebird.oms.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author qiuxj 创建于 2009-12-6
 *
 */
public class SeqCreatorFactory {
	
	private static final String SEQ_PREFIX = "ZB";
	
	public SeqCreatorFactory() {
		
	}
	
	public String getZbSeq() {
		return this.getSeq(SEQ_PREFIX);
	}
	
	public synchronized String getSeq(String seqPrefix) {
		Integer temp = new Double(Math.random() * 10000).intValue();

		DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
		
		Date date = new Date();
		Long millis = System.currentTimeMillis();
		String tailLong = millis.toString();
		String tailtemp = temp.toString();
		String orderId = null;
		try {
			orderId = df.format(date)
					+ millis.toString().substring(tailLong.length() - 2, tailLong.length())
					+ tailtemp.substring(tailtemp.length() - 2, tailtemp.length());
		} catch (Exception e) {
			while (orderId == null) {
				orderId = df.format(date)
						+ millis.toString().substring(tailLong.length() - 2, tailLong.length())
						+ tailtemp.substring(tailtemp.length() - 2, tailtemp.length());
			}
		}
		return seqPrefix + orderId;
	}
	
	public static void main(String[] args) {
		SeqCreatorFactory factory = new SeqCreatorFactory();
		System.err.println(factory.getZbSeq());
	}

}
